﻿using System.Collections.Generic;
using Ycg.Utility;

namespace Ycg.Logging.Targets
{
    public class TargetFactory
    {
        private static Dictionary<TargetType, LogTarget> TargetInstances = new Dictionary<TargetType, LogTarget>();

        public static LogTarget GetInstance(TargetType targetType)
        {
            if (!TargetInstances.ContainsKey(targetType))
            {
                string targetName = targetType.ToString();
                string fullName = string.Format(targetType == TargetType.EventLog
                                            ? "Ycg.Logging.Targets.{0}Target"
                                            : "Ycg.Logging.Targets.{0}LogTarget", targetName);
                TargetInstances.Add(targetType, ObjectHelper.CreateInstance<LogTarget>(fullName));
            }
            return TargetInstances[targetType];
        }
    }
}
